import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import './assets/main.css'

const app = createApp(App)

// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.use(ElementPlus, {
  locale: zhCn,
})

// 添加全局错误处理
app.config.errorHandler = (err, vm, info) => {
  console.error('Vue Error:', err)
  console.error('Error Info:', info)
}

window.onerror = function(message, source, lineno, colno, error) {
  // 忽略 ResizeObserver 错误
  if (message.includes('ResizeObserver')) {
    return
  }
  console.error('Global Error:', {
    message,
    source,
    lineno,
    colno,
    error
  })
}

// 添加 ResizeObserver 错误处理
const resizeHandler = (entries) => {
  window.requestAnimationFrame(() => {
    for (const entry of entries) {
      // 处理 resize 事件
    }
  })
}

const ro = new ResizeObserver(resizeHandler)

// 先挂载路由
app.use(router)

app.mount('#app') 